# Include all custom CHE_* properties that user may has defined in its che.env file
<% ENV.each do |k,v| -%>
<% if k.include? "CHE_" then  -%>
<%= k + '=' + v %>
<% end -%>
<% end -%>


CHE_IP=<%= scope.lookupvar('che::che_ip') %>
CHE_PORT=<%= scope.lookupvar('che::che_port') %>
#DOCKER_HOST=<%= scope.lookupvar('che::docker_host') %>
#DOCKER_MACHINE_HOST=<%= scope.lookupvar('che::docker_ip') %>

<% if @che_jmx_enabled == "true" -%>
CATALINA_OPTS=-Dcom.sun.management.jmxremote=true -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/conf/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false
<% end -%>

<% if scope.lookupvar('che::che_env') != "production" -%>
CHE_DEBUG_SERVER=true
JPDA=jpda
CHE_ASSEMBLY=<%= scope.lookupvar('che::che_assembly') %>
JPDA_ADDRESS=<%= scope.lookupvar('che::che_debug_port') %>
<% if scope.lookupvar('che::che_debug_suspend') == "true" %>JPDA_SUSPEND=y<% end %>
<% end -%>

CHE_MULTIUSER=<%= scope.lookupvar('che::che_multiuser') %>
<% if scope.lookupvar('che::che_multiuser') == 'true' -%>
<% if scope.lookupvar('che::che_port') == '8080' -%>
CHE_DOCKER_NETWORK=che_che-network
<% else -%>
CHE_DOCKER_NETWORK=che<%= scope.lookupvar('che::che_port') %>_che-network
<% end -%>
<% else -%>
CHE_DOCKER_NETWORK=bridge
<% end -%>

<% if scope.lookupvar('che::che_single_port') == 'true' -%>
<% if ! @che_docker_ip_external.empty? -%>
CHE_INFRA_DOCKER_MASTER__API__ENDPOINT=http://<%= scope.lookupvar('che::che_docker_ip_external') -%>:<%= scope.lookupvar('che::che_port') -%>/api
CHE_INFRA_DOCKER_MASTER__WEBSOCKET__ENDPOINT=ws://<%= scope.lookupvar('che::che_docker_ip_external') -%>:<%= scope.lookupvar('che::che_port') -%>/api/websocket
<% else -%>
CHE_INFRA_DOCKER_MASTER__API__ENDPOINT=http://<%= scope.lookupvar('che::docker_ip') -%>:<%= scope.lookupvar('che::che_port') -%>/api
CHE_INFRA_DOCKER_MASTER__WEBSOCKET__ENDPOINT=ws://<%= scope.lookupvar('che::docker_ip') -%>:<%= scope.lookupvar('che::che_port') -%>/api/websocket
<% end -%>
<% end -%>

CHE_DATABASE=/data/storage
CHE_WORKSPACE_STORAGE=<%= scope.lookupvar('che::che_instance') %>/data/workspaces
CHE_WORKSPACE_STORAGE__MASTER__PATH=/data/workspaces
CHE_LOGS_DIR=/logs
CHE_WORKSPACE_LOGS=/logs/machines
CHE_TEMPLATE_STORAGE=/data/templates


<% if ! @che_http_proxy.empty? or ! @che_https_proxy.empty? -%>
JAVA_HTTP_PROXY_SET=-Dhttp.proxySet=true
<% end -%>
<% if ! @che_http_proxy.empty? -%>
<% if ! @che_http_proxy.empty? and @che_http_proxy.include? '@' -%>
JAVA_HTTP_USER_NAME=-Dhttp.proxyUser=<%= @che_http_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[0].split(':')[0] %>
JAVA_HTTP_USER_PASSWORD=-Dhttp.proxyPassword=<%= @che_http_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[0].split(':')[1] %>
JAVA_HTTP_PROXY_HOST=-Dhttp.proxyHost=<%= @che_http_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[1].split(':')[0] %>
JAVA_HTTP_PROXY_PORT=-Dhttp.proxyPort=<%= @che_http_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[1].split(':')[1].gsub(/\/.*/,'') %>
<% else -%>
JAVA_HTTP_PROXY_HOST=-Dhttp.proxyHost=<%= @che_http_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split(':')[0] %>
JAVA_HTTP_PROXY_PORT=-Dhttp.proxyPort=<%= @che_http_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split(':')[1].gsub(/\/.*/,'') %>
<% end -%>
<% end -%>
<% if ! @che_https_proxy.empty? -%>
<% if @che_https_proxy.include? '@' -%>
JAVA_HTTPS_USER_NAME=-Dhttps.proxyUser=<%= @che_https_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[0].split(':')[0] %>
JAVA_HTTPS_USER_PASSWORD=-Dhttps.proxyPassword=<%= @che_https_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[0].split(':')[1] %>
JAVA_HTTPS_PROXY_HOST=-Dhttps.proxyHost=<%= @che_https_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[1].split(':')[0] %>
JAVA_HTTPS_PROXY_PORT=-Dhttps.proxyPort=<%= @che_https_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[1].split(':')[1].gsub(/\/.*/,'') %>
<% else -%>
JAVA_HTTPS_PROXY_HOST=-Dhttps.proxyHost=<%= @che_https_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split(':')[0] %>
JAVA_HTTPS_PROXY_PORT=-Dhttps.proxyPort=<%= @che_https_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split(':')[1].gsub(/\/.*/,'') %>
<% end -%>
<% end -%>
<% if ! @che_no_proxy.empty? -%>
JAVA_NO_PROXY=-Dhttp.nonProxyHosts='<%= @che_no_proxy.gsub(/^https?\:\/\//, '').gsub(/^www./,'').gsub(/[[:space:]]/,'').split(",").uniq.join("|") %>'
<% end -%>
JAVA_OPTS=-XX:MaxRAMFraction=2 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Dsun.zip.disableMemoryMapping=true -Xms20m <% if ! @che_http_proxy.empty? or ! @che_https_proxy.empty? -%>$JAVA_HTTP_PROXY_SET<% end -%> <% if ! @che_http_proxy.empty? -%>$JAVA_HTTP_PROXY_HOST $JAVA_HTTP_PROXY_PORT<% end -%> <% if ! @che_https_proxy.empty? -%>$JAVA_HTTPS_PROXY_HOST $JAVA_HTTPS_PROXY_PORT<% end -%><%- if ! @che_no_proxy.empty? -%> $JAVA_NO_PROXY<% end -%><% if @che_http_proxy.include? '@' -%> $JAVA_HTTP_USER_NAME $JAVA_HTTP_USER_PASSWORD<% end -%><% if @che_https_proxy.include? '@' -%> $JAVA_HTTPS_USER_NAME $JAVA_HTTPS_USER_PASSWORD<% end %>

# http proxy options for jvm
CHE_WORKSPACE_HTTP__PROXY__JAVA__OPTIONS=<% if ! @http_proxy_for_che_workspaces.empty? or ! @https_proxy_for_che_workspaces.empty? -%>-Dhttp.proxySet=true<% end -%><% if ! @http_proxy_for_che_workspaces.empty? -%><% if ! @http_proxy_for_che_workspaces.empty? and @http_proxy_for_che_workspaces.include? '@' -%> -Dhttp.proxyUser=<%= @http_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[0].split(':')[0] %> -Dhttp.proxyPassword=<%= @http_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[0].split(':')[1] %> -Dhttp.proxyHost=<%= @http_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[1].split(':')[0] %> -Dhttp.proxyPort=<%= @http_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[1].split(':')[1].gsub(/\/.*/,'') %><% else -%> -Dhttp.proxyHost=<%= @http_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split(':')[0] %> -Dhttp.proxyPort=<%= @http_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split(':')[1].gsub(/\/.*/,'') %><% end -%><% end -%><% if ! @https_proxy_for_che_workspaces.empty? -%><% if @https_proxy_for_che_workspaces.include? '@' -%> -Dhttps.proxyUser=<%= @https_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[0].split(':')[0] %> -Dhttps.proxyPassword=<%= @https_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[0].split(':')[1] %> -Dhttps.proxyHost=<%= @https_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[1].split(':')[0] %> -Dhttps.proxyPort=<%= @https_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split('@')[1].split(':')[1].gsub(/\/.*/,'') %><% else -%> -Dhttps.proxyHost=<%= @https_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split(':')[0] %> -Dhttps.proxyPort=<%= @https_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split(':')[1].gsub(/\/.*/,'') %><% end -%><% end -%><% if ! @che_no_proxy.empty? -%> -Dhttp.nonProxyHosts='<%= @no_proxy_for_che_workspaces.gsub(/^https?\:\/\//, '').gsub(/^www./,'').split(",").uniq.join("|") %>|'<% end -%>

# Enable single port options
<% if scope.lookupvar('che::che_single_port') == "true" -%>
CHE_INFRA_DOCKER_URL__REWRITER=singleport

<% if scope.lookupvar('che::che_multiuser') == 'true' -%>
<% if scope.lookupvar('che::che_single_port') == 'true' and scope.lookupvar('che::che_single_port_wildcard_domain_ipless') == 'true' -%>
CHE_KEYCLOAK_AUTH__SERVER__URL=http://keycloak.<%= scope.lookupvar('che::che_single_port_wildcard_domain_host') -%>/auth
<% elsif ! @che_docker_ip_external.empty? -%>
CHE_KEYCLOAK_AUTH__SERVER__URL=http://keycloak.<%= scope.lookupvar('che::che_docker_ip_external') -%>.<%= scope.lookupvar('che::che_single_port_wildcard_domain_host') -%>:<%= scope.lookupvar('che::che_port') -%>/auth
<% else -%>
CHE_KEYCLOAK_AUTH__SERVER__URL=http://keycloak.<%= scope.lookupvar('che::docker_ip') -%>.<%= scope.lookupvar('che::che_single_port_wildcard_domain_host') -%>:<%= scope.lookupvar('che::che_port') -%>/auth
<% end -%>
<% end -%>
<% end -%>
